package com.reverie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.reverie.common.pojo.CommonPageReq;
import com.reverie.dto.req.ShopperQueryParam;
import com.reverie.entity.Shopper;
import com.reverie.mapper.ShopperMapper;
import com.reverie.service.IShopperService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class ShopperServiceImpl extends ServiceImpl<ShopperMapper, Shopper> implements IShopperService {
    @Override
    public Page<Shopper> queryPage(CommonPageReq<ShopperQueryParam> queryPageParam) {
        ShopperQueryParam shopperQueryParam = queryPageParam.getQueryParam();
        QueryWrapper<Shopper> wrapper = new QueryWrapper<>();
        if (shopperQueryParam != null) {
            if(StringUtils.hasLength(shopperQueryParam.getMobile())){
                wrapper.lambda().eq(Shopper::getMobile,shopperQueryParam.getMobile());
            }
            if(StringUtils.hasLength(shopperQueryParam.getName())){
                wrapper.lambda().like(Shopper::getRealname,shopperQueryParam.getName());
            }
        }
        Page<Shopper> shopperPage = new Page<>(queryPageParam.getPageNo(),queryPageParam.getPageSize());
        page(shopperPage,wrapper);
        return shopperPage;
    }
}
